home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / DTS.StyleChat / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  3.3 KB  |  131 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        IdleTasks.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This function is called when a null event is received.  Do appropriate tasks
  20. ** for null event situations, such as handling balloon help for window. */
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  29. #include "App.protos.h"        /* Get the prototypes for application.            */
  30.  
  31. extern OSType    gAppWindowType;
  32. extern short    gDialogErr;
  33.  
  34. Boolean            gStartingUp = true;
  35.  
  36.  
  37.  
  38. /*****************************************************************************/
  39. /*****************************************************************************/
  40.  
  41. #ifdef applec
  42. #pragma segment IdleTasks
  43. #endif
  44.  
  45. /*****************************************************************************/
  46. /*****************************************************************************/
  47.  
  48.  
  49.  
  50. void    DoIdleTasks(EventRecord *event)
  51. {
  52. #ifndef __MWERKS__
  53. #pragma unused (event)
  54. #endif
  55.  
  56.     WindowPtr        ww;
  57.     FileRecHndl        ff;
  58.     ControlHandle    ctl;
  59.     EventRecord        evt;
  60.     TEHandle        te;
  61.     Rect            rr;
  62.     KeyMap            kk;
  63.     short            mm;
  64.  
  65.     static long    waitSome;
  66.  
  67.     if (gStartingUp) {
  68.         if (FrontWindow()) {
  69.             gStartingUp = false;
  70.             waitSome = 0;
  71.             IsCtlEvent(nil, event, nil, nil);
  72.             return;
  73.         }
  74.         if (!waitSome) waitSome = TickCount() + 30;
  75.         else {
  76.             if (waitSome < TickCount()) {
  77.                 gStartingUp = false;
  78.                 waitSome    = 0;
  79.                 gDialogErr  = NewDocumentWindow(nil, gAppWindowType, true);
  80.                 if (gDialogErr)
  81.                     NewDocumentWindow(nil, 'ERR#', false);
  82.             }
  83.         }
  84.         IsCtlEvent(nil, event, nil, nil);
  85.         return;
  86.     }
  87.  
  88.     for (ww = nil; (ww = GetNextWindow(ww, gAppWindowType)) != nil;) {
  89.         ff = (FileRecHndl)GetWRefCon(ww);
  90.         if ((*ff)->connect.connected == 1) {
  91.             CNum2Ctl(ww, 1010, &ctl);
  92.             (*ctl)->contrlVis = false;
  93.             BeginFrame(ww);
  94.             CNum2Ctl(ww, 1020, &ctl);
  95.             ShowStyledControl(ctl);
  96.             CNum2Ctl(ww, 1000, &ctl);
  97.             ShowStyledControl(ctl);
  98.             EndFrame(ww);
  99.             (*ff)->connect.connected++;
  100.             BeginContent(ww);
  101.             SendMessage(ff, kStylMssg);
  102.             SendMessage(ff, kTextMssg);
  103.             EndContent(ww);
  104.         }
  105.     }
  106.  
  107.     if (TSMTEAvailable()) TSMEvent(event);
  108.  
  109.     GetKeys(kk);
  110.     mm  = (kk[1] & 0x8000) ? (cmdKey    ) : 0;
  111.     mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
  112.     mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
  113.     mm |= (kk[1] & 0x0001) ? (shiftKey  ) : 0;
  114.     evt.what      = nullEvent;        /* Make valid null event, with modifiers. */
  115.     evt.modifiers = mm;
  116.     IsCtlEvent(nil, &evt, nil, nil);
  117.  
  118.     ww = CTETargetInfo(&te, &rr);
  119.     if (ww) {
  120.         if (rr.left < -8192)        /* If TextEdit control is in the frame...  */
  121.             BeginFrame(ww);            /* Set clipping to the frame area.           */
  122.         else
  123.             BeginContent(ww);        /* Else set clipping to the document area. */
  124.         CTEIdle();
  125.         EndContent(ww);                /* EndContent can be used to close a BeginFrame. */
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.